<?php
// no direct access
defined('_JEXEC') or die('Restricted access');

jimport( 'joomla.application.component.view' );

class QcalcViewMarshrutization extends Jview {

	function display($tpl = null) {

		$model	=& $this->getModel();

		
		$user =& JFactory::getUser();
		$user->city = $model->getCityById($user->city_id);
		
		$this->assignRef('user', $user);
		
		if ($user->company_id) {
		   $company = $model->getCompanyById($user->company_id);
		}
      
      $date = JRequest::getVar('date', false, 'get', 'db_string');
      if ($date) {
         $d = explode('.', $date);
         if (count($d) == 3)
            $date_db = @$d[2] ."-". @$d[1] ."-". @$d[0] ."";
         else {
            $date = false; $date_db = false; }
      } else {
         $date = false; $date_db = false; }
      //die($date);
		
		$m_list     = $model->getMList($user->id);
      $a_list     = $model->getMListArch($user->id,$date_db);
		$poluchatel = $model->getPoluchatel($user->id);
		$calcs      = $model->getCalcs($user->id);
		
		foreach ($calcs AS &$c) {
          $c->marshrut = unserialize($c->marshrut);
          $c->gruz     = unserialize($c->gruz);
          $c->calc     = unserialize($c->calc);
      }
		
		//print_r($company);
		
		$this->assignRef('company',    $company[0]);
		$this->assignRef('m_list',     $m_list);
      $this->assignRef('a_list',     $a_list);
		$this->assignRef('poluchatel', $poluchatel);
		$this->assignRef('calcs',      $calcs);
      $this->assignRef('date',       $date);

		parent::display($tpl);

	}

}
?>